
package com.healthdata.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.healthdata.dao.HealthExpenditure2021Mapper;
import com.healthdata.entity.HealthExpenditure2021;
import com.healthdata.service.HealthExpenditure2021Service;
import com.healthdata.vo.HealthExpenditure2021VO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

@Service
public class HealthExpenditure2021ServiceImpl implements HealthExpenditure2021Service {

    @Autowired
    private HealthExpenditure2021Mapper healthExpenditure2021Mapper;

    @Override
    public List<HealthExpenditure2021VO> listAll() {
        List<HealthExpenditure2021> entityList = healthExpenditure2021Mapper.selectList(null);
        return convertToVOList(entityList);
    }

    @Override
    public HealthExpenditure2021VO getById(Integer id) {
        HealthExpenditure2021 entity = healthExpenditure2021Mapper.selectById(id);
        return entity != null ? convertToVO(entity) : null;
    }

    @Override
    public List<HealthExpenditure2021VO> listByRegion(String region) {
        QueryWrapper<HealthExpenditure2021> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("region", region);
        List<HealthExpenditure2021> entityList = healthExpenditure2021Mapper.selectList(queryWrapper);
        return convertToVOList(entityList);
    }

    /**
     * 将实体列表转换为VO列表
     * @param entityList 实体列表
     * @return VO列表
     */
    private List<HealthExpenditure2021VO> convertToVOList(List<HealthExpenditure2021> entityList) {
        List<HealthExpenditure2021VO> voList = new ArrayList<>();
        for (HealthExpenditure2021 entity : entityList) {
            voList.add(convertToVO(entity));
        }
        return voList;
    }

    /**
     * 将实体转换为VO
     * @param entity 实体
     * @return VO
     */
    private HealthExpenditure2021VO convertToVO(HealthExpenditure2021 entity) {
        HealthExpenditure2021VO vo = new HealthExpenditure2021VO();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
}